import React, { Component } from 'react'
import { Route, Redirect } from 'react-router-dom';
import styles from './Content.module.scss'
import { RouteWithSubRoutes, routes } from '../router'
import DecisionDetail from '../router/DecisionDetail';
import CommonDetail from './../components/common/CommonDetail'
import AdDetail from './../components/common/AdDetail'
import Register from './../router/Register/Register'
import ModifyPwd from './../router/ModifyPwd/ModifyPwd'
import ResetPwd from './../router/ResetPwd/ResetPwd'
import SpecialList from './../components/Home/SpecialList'
import SpecialTotal from './../components/Home/SpecialTotal'
import Viewpoint from './../components/Home/Viewpoint'
import SearchResult from './../components/common/SearchResult'
import QA from './../components/Home/QA'
import About from './../router/About/About'
import ProfessorDetail from './../router/ProfessorDetail/ProfessorDetail'
import Result from '../router/Result'
import { backTop } from './../util/index'
import { withRouter } from 'react-router-dom'

class Content extends Component {

  goToTop() {
    backTop()
  }

  goHome() {
    this.props.history.replace('/mainPage/main')
  }

  render() {
    return (
      <div className={styles.content}>
        <Route exact path='/mainPage' render={() => <Redirect to={'/mainPage/main'} />} />

        {routes.map((route, i) => (
          <RouteWithSubRoutes key={i} {...route} />
        ))}

        {/* 智库成果 */}
        <Route path='/mainPage/result' component={Result} />

        {/* 决策调研 - 详情 */}
        <Route path='/mainPage/pageDetail/:pageType/:id' component={DecisionDetail} />

        {/* 详情 */}
        <Route path='/mainPage/commonDetail/:pageType/:id' component={CommonDetail} />
        <Route path='/mainPage/AdDetail/themeAd/:id' component={AdDetail} />

        {/* 分院所 */}
        <Route path='/mainPage/SpecialList/:id' component={SpecialList} />

        {/* 专刊总列表 */}
        <Route path='/mainPage/SpecialTotal' component={SpecialTotal} />

        {/* 学者观点 */}
        <Route path='/mainPage/Viewpoint' component={Viewpoint} />

        {/* 问卷调查 */}
        <Route path='/mainPage/QA' component={QA} />

        {/* 专家详情 */}
        <Route path='/mainPage/professorDetail/thinkTankData/:id' component={ProfessorDetail} />

        {/* 关于我们 */}
        <Route path='/mainPage/zhikuAbout' component={About} />

        {/* 搜索结果页 */}
        <Route path='/mainPage/SearchResult/:searchKey' component={SearchResult} />

        {/* 注册 */}
        <Route path='/mainPage/register' component={Register} />

        {/* 重置密码 */}
        <Route path='/mainPage/resetPwd' component={ResetPwd} />

        {/* 修改密码 */}
        <Route path='/mainPage/modifyPwd' component={ModifyPwd} />

        <div className="go_to_top">
          <div className="backBg" onClick={() => this.goHome()}>
            返回首页
          </div>
          <div className="backBg" onClick={() => this.goToTop()}>
            返回顶部
          </div>
        </div>

      </div>
    )
  }
}
export default withRouter(Content)